﻿using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;

namespace SampleSite.Areas.Limestone.Services
{
    public static class MenuHelperExtensions
    {
        public static MvcHtmlString MenuLink(this HtmlHelper helper,
                                       string text,
                                       string action,
                                       string controller,
                                       object routeValues,
                                       object htmlAttributes,
                                       string currentClass)
        {
            var attributes = new RouteValueDictionary(htmlAttributes);
            string currentController = helper.ViewContext.RouteData.Values["controller"] as string ?? "home";
            string currentAction = helper.ViewContext.RouteData.Values["action"] as string ?? "index";
            string page = string.Format("{0}:{1}", currentController, currentAction).ToLower();
            string thisPage = string.Format("{0}:{1}", controller, action).ToLower();
            attributes["class"] = (page == thisPage) ? currentClass : "";
            return helper.ActionLink(text, action, controller, new RouteValueDictionary(routeValues), attributes);
        }
    }
}